{extend name="main"}
{block name="style"}
<style type="text/css">
	.flex-lable{width: 100px;color: #6c757d;text-align: right;padding-right: 10px;}
	.w-100px{width: 100px;}
</style>
{/block}
{block name="body"}
<div class="bg-white mb-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search" label-position="right" class="flex py-3">

	  <el-form-item label="搜索类型" prop="search_type" class="flex mb-0 pl-3">
	  	<el-select v-model="search.search_type" placeholder="请选择" class="w-100px">
		    <el-option key="id"label="职位ID"value="id"></el-option>
		    <el-option key="title"label="职位名称"value="title"></el-option>
		    <el-option key="company_id"label="公司ID"value="company_id"></el-option>
		    <el-option key="uid"label="UID"value="uid"></el-option>
		    <el-option key="company_name"label="公司名"value="company_name"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="企业认证" prop="attestation" class="flex mb-0 pl-3">
	  	<el-select v-model="search.attestation" placeholder="请选择" class="w-100px">
		    <el-option key="all"label="全部"value="all"></el-option>
		    <el-option v-for="v in attestation" :key="v.value":label="v.title":value="v.value"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item label="审核" prop="examine" class="flex mb-0 pl-3">
	  	<el-select v-model="search.examine" placeholder="请选择" class="w-100px">
		    <el-option key="all"label="全部"value="all"></el-option>
		    <el-option :key="0"label="未审核":value="0"></el-option>
		    <el-option :key="1"label="已通过":value="1"></el-option>
		    <el-option :key="2"label="未通过":value="2"></el-option>
		</el-select>
	  </el-form-item>

	  <el-form-item :label="getSearchType()" prop="key" class="flex mb-0 pl-3">
	    <el-input v-model="search.key" placeholder="请输入你想搜索的关键词"></el-input>
	  </el-form-item>

	  <el-form-item class="flex mb-0 pl-3">
	    <el-button type="primary" @click="initHtml">查询</el-button>
	    <el-button @click="resetForm('search')">重置</el-button>
	  </el-form-item>
	</el-form>
</div>
<div class="bg-white p-3">
	<div class="table-responsive">
		<el-table
			ref="tableList"
	      	:data="tableData"
    		v-loading="search.ajax"
    		style="width: 100%;"
    		header-cell-class-name="table-header-DDE6FB"
    		@selection-change="handleSelectionChange">
		  <el-table-column
			  type="selection"
			  width="55">
		  </el-table-column>
	      <el-table-column
	        prop="id"
	        label="ID"
	        width="100">
	      </el-table-column>
	      <el-table-column
	        label="职位名称/发布企业"
	        min-width="200">
		      <template slot-scope="scope">
		      	<div>
		      	<el-link type="primary" :href="'{:config('web.url')}/jobs/'+scope.row.id+'.html'" target="_blank" :underline="false">{{scope.row.title}}</el-link>
		      	</div>
		      	<div>
		      	<el-link :href="'{:config('web.url')}/company/'+scope.row.company_id+'.html'" target="_blank" :underline="false">{{scope.row.company_name}}</el-link>
		      	</div>
		      	<div class="small">{{scope.row.contacts}}<span class="mx-1">·</span>{{scope.row.contacts_mobile}}</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="简历"
	        width="140">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div>已投递：{{scope.row.delivery_resume}}</div>
		      	<div>未查看：{{scope.row.delivery_resume_not}}</div>
		      	<div>已面试：{{scope.row.invite_an_interview}}</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="企业认证"
	        width="120">
		      <template slot-scope="scope">
		      	<transition>
		      		<el-link v-for="v in attestation" :type="v.type" 
		      		v-if="scope.row.attestation==v.value"
		      		:underline="false">{{v.title}}</el-link>
				</transition>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="会员"
	        width="140">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div>{{scope.row.vip_title}}</div>
		      	<div v-if="scope.row.company_vip_time">{{scope.row.company_vip_time}}</div>
		      	<div v-else>不限</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        prop="delivery_resume"
	        label="投递/浏览"
	        width="160">
		      <template slot-scope="scope">
		      <div class="small">
		      	<div>浏览：{{scope.row.view}}</div>
		      	<div>来源：{{scope.row.app_name}}</div>
		      </div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="审核/状态"
	        width="120">
		      <template slot-scope="scope">
		      	<div>
				<div class="mb-1">
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.examine==1 || scope.row.examine=='loading'"
		      		:loading="scope.row.examine=='loading'">已审核</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else-if="scope.row.examine==0 || scope.row.examine=='loading'" 
		      		:loading="scope.row.examine=='loading'">待审核</el-button>
		      		<el-button type="danger" size="minism" 
		      		v-else-if="scope.row.examine==2 || scope.row.examine=='loading'" 
		      		:loading="scope.row.examine=='loading'">未通过</el-button>
				</transition>
				</div>
				<div>
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="scope.row.status==1 || scope.row.status=='loading'"
		      		:loading="scope.row.status=='loading'">展示中</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else-if="scope.row.status==0 || scope.row.status=='loading'" 
		      		:loading="scope.row.status=='loading'">未展示</el-button>
		      		<el-button type="danger" size="minism" 
		      		v-else>已删除</el-button>
				</transition>
				</div>
				</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="时间线"
	        width="240">
		      <template slot-scope="scope">
		      	<div class="small">
		          <div>创建时间: {{ scope.row.create_time }}</div>
		          <div>更新时间: {{ scope.row.update_time }}</div>
		          <div>刷新时间: {{ scope.row.refresh_time }}</div>
		          <div v-if="scope.row.delete_time">删除时间: {{ scope.row.delete_time }}</div>
		          <div v-if="scope.row.top_time">置顶结束: {{ scope.row.top_time }}</div>
		          <div v-if="scope.row.recommend_time">推荐结束: {{ scope.row.recommend_time }}</div>
		          <div v-if="scope.row.urgent_time">紧急招聘结束: {{ scope.row.urgent_time }}</div>
		      	</div>
		      </template>
	      </el-table-column>
	      <el-table-column
	        label="/"
	        width="160">
		      <template slot-scope="scope">
		        <el-button
		            type="success"
		            plain
		            round
		            size="minism"
		            @click="setJobsDelete(scope)">
		            恢复
		        </el-button>
		        <el-button
		            type="danger"
		            plain
		            round
		            size="minism"
		            @click="setJobsDeleteForce(scope)">
		            彻底删除
		        </el-button>
		      </template>
	      </el-table-column>
	    </el-table>
	</div>
	<div class="table-responsive py-3 text-center">
		<el-pagination
		  background
	      @size-change="handleSizeChange"
	      @current-change="handleCurrentChange"
	      :current-page="search.page"
	      :page-sizes="[10,50,100,200,500,1000]"
	      :page-size="search.pageSize"
	      layout="total, sizes, prev, pager, next, jumper"
	      :total="search.total">
	    </el-pagination>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="attestation"}
	var attestation=[];
	{else/}
	var attestation={:json_encode($attestation,JSON_UNESCAPED_UNICODE)};
	{/empty}
	{empty name="role"}
	var role=[];
	{else/}
	var role={:json_encode($role,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			showLog:false,
			role:role,
			labelPosition:'right',
			attestation:attestation,
			search:{
				{notempty name=":request()->get('jobs_id')"}
				search_type:'id',
				key:'{:request()->get('jobs_id')}',
				{elseif request()->get('uid')/}
				search_type:'uid',
				key:'{:request()->get('uid')}',
				{elseif request()->get('name')/}
				search_type:'name',
				key:'{:request()->get('name')}',
				{elseif request()->get('mobile')/}
				search_type:'mobile',
				key:'{:request()->get('mobile')}',
				{elseif request()->get('email')/}
				search_type:'email',
				key:'{:request()->get('email')}',
				{else/}
				search_type:'id',
				key:'',
				{/notempty}
				attestation:'all',
				examine:{:request()->get('examine',"\'all\'")},
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
			multipleSelection:[],
			multipleSelectionIndex:0,
			dialogVisible:false,
			rowData:{},
			top:0,
			recommend:0,
			urgent:0,
			accumulation:0,
			form:{
				ajax:false,
				status:1,
				notice:1,
				msg:''
			},
	        rules: {
	          status: [
	            { required: true, message: '请选择审核结果', trigger: 'change' },
	          ],
	          msg: [
	            { required: true, message: '请输入审核结果', trigger: 'blur' },
	          ],
	        }
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
		    toggleSelection(rows) {
		        if (rows) {
		          rows.forEach(row => {
		            this.$refs.tableList.toggleRowSelection(row);
		          });
		        } else {
		          this.$refs.tableList.clearSelection();
		        }
		    },
		    handleSelectionChange(val) {
		        this.multipleSelection = val;
		    },
	      	cancelRefuseWinSubmit(done){
	      		this.rowData={};
	      		this.$refs.form&&this.$refs.form.resetFields();
	      		typeof done==='function'&&done();
				this.dialogVisible=false;
	      	},
			openRefuseWin(row){
				if (row){
					this.rowData=row;
				}else{
					if (this.multipleSelection.length<1)return XYBase.msg('请选择职位');
				}
				this.dialogVisible=true;
			},
			submitForm(formName) {
				var _this=this;
				_this.$refs[formName].validate((valid) => {
				  if (valid) {
				  	if (this.rowData.id) {
					  	_this.setJobsExamine(_this.rowData,_this.form.status);
				  	}else{
						_this.dialogVisible=false;
				  		_this.setJobsExamineALL();
				  	}
				  } else {
					return XYBase.warning('请先把表单填写完整。');
				  }
				});
			},
	    	setJobsDelete(scope){
	    		var _this=this;
		        _this.$confirm('确定恢复《'+scope.row.company_name+'》公司的《'+scope.row.title+'》职位吗？', '提示', {
		          confirmButtonText: '恢复',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
		    		$.getJSON('/jobs/setJobsDelete/'+scope.row.id,function(ret){
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.tableData.splice(scope.$index,1);
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
		        }).catch(() => {
    				XYBase.msg('已取消');
		        });
	    	},
	    	setJobsDeleteForce(scope){
	    		var _this=this;
		        _this.$confirm('确定彻底《'+scope.row.company_name+'》公司的《'+scope.row.title+'》职位吗？', '提示', {
		          confirmButtonText: '确定',
		          cancelButtonText: '取消',
		          type: 'error'
		        }).then(() => {
		    		$.getJSON('/jobs/setJobsDelete/'+scope.row.id+'?force=1',function(ret){
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.tableData.splice(scope.$index,1);
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
		        }).catch(() => {
    				XYBase.msg('已取消');
		        });
	    	},
	    	getSearchType(){
	    		var text='职位ID';
	    		switch(this.search.search_type){
	    			case 'id':
	    				text='职位ID';
	    				break;
	    			case 'title':
	    				text='职位名称';
	    				break;
	    			case 'company_id':
	    				text='公司ID';
	    				break;
	    			case 'uid':
	    				text='UID';
	    				break;
	    			case 'company_name':
	    				text='公司名';
	    				break;
	    		}
	    		return text;
	    	},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				this.search.page=val;
	          	this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			},
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}